package io.ouka.jvm.hotspot.selfread.read;

import io.ouka.jvm.hotspot.selfread.InstanceKlass;
import io.ouka.jvm.hotspot.selfread.constant.FinalConstant;
import io.ouka.jvm.hotspot.selfread.util.DataTranslate;

/**
 * @author Ouka
 */
public class MainVersionReader extends AbstractReader {
    public MainVersionReader() {
        this.iReader = new SecondVersionReader();
    }

    @Override
    public void preRead(byte[] content) {
        int size = 0;
        byte[] bytes = new byte[FinalConstant.u2];
        for (int i = index; i < content.length; i++) {
            if (size<=FinalConstant.u2-1)
            {bytes[size] = content[i];size++;}
            if (i>index+FinalConstant.u2-1){
                this.selfContent = bytes;
                index= index+FinalConstant.u2;
                return ;
            }
        }
    }

    @Override
    public void read() {
        instanceKlass.setMainVersion(DataTranslate.byteToUnsignedShort(selfContent));
    }

}
